//
//  AppDelegate+UpdateVersion.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/10/10.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "AppDelegate+UpdateVersion.h"
@interface APPModel()
@end

@implementation APPModel
- (instancetype)initWithDict:(NSDictionary *)dict{
    self = [super init];
    if (self) {
        
        [self setValuesForKeysWithDictionary:dict];
    }
    return self;
}

+ (instancetype)initWithDict:(NSDictionary *)dict{
    return [[self alloc] initWithDict:dict];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{
}
@end
@implementation AppDelegate (UpdateVersion)
+ (instancetype)shareAppDelegate{
    return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
- (void)updateVersionWithApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    __block NSURLSessionTask *task;
    
    task = [CYHttps POST:API_updateVersion parameters:@{@"server_version":@"1",@"app_id":@"1"} success:^(id data) {
        DeLog(@"update versino %@",data);
        NSDictionary *dict = @{@"appname":@"彩云",@"server_version":@"2.0l.1",@"updateurl":@"https:www.baidu.com"};
        APPModel *model = [APPModel initWithDict:dict];
        [CYAlert showInWindowWithTitle:@"" message:[NSString stringWithFormat:@"您的应用发现最新版本(%f),请立即前往更新",model.server_version] enterComplete:^{
            [[AppDelegate shareAppDelegate] openURL:model.updateurl];
            [task cancel];
            task = nil;
        }];
    } failure:nil];
    
}
@end
